import { createStore } from 'vuex';
import VuexPersistence from 'vuex-persist'; // 确保使用正确的导入方法

const vuexLocal = new VuexPersistence({
    storage: window.localStorage // 使用 localStorage 作为存储介质
});
export default createStore({
    state: {
        problemId: null, // 存储上传问题的ID
        testGroupMongoId: null,
        testGroupId: null,
        results: {}
    },
    mutations: {
        setProblemId(state, id) {
            state.problemId = id; // 设置问题ID的mutation
        },
        setTestGroupMongoId(state, id) {
            state.testGroupMongoId = id; // 设置测试组Mongo ID的mutation
        },
        setTestGroupId(state, id) {
            state.testGroupId = id; // 设置测试组ID的mutation
        },
        setResult(state, { id, data }) {
            state.results[id] = data; // 存储结果数据
        }
    },
    actions: {
        updateProblemId({ commit }, id) {
            commit('setProblemId', id); // 触发mutation来更新问题ID
        },
        updateTestGroupMongoId({ commit }, id) {
            commit('setTestGroupMongoId', id); // 触发mutation来更新测试组Mongo ID
        },
        updateTestGroupId({ commit }, id) {
            commit('setTestGroupId', id); // 触发mutation来更新测试组ID
        },
        storeResult({ commit }, { id, data }) {
            commit('setResult', { id, data }); // 存储结果
        }
    },
    plugins:[vuexLocal.plugin]
});
